<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>全部评价</title>
		<%@include file="../common/common.jsp" %>
		<!-- <link rel="stylesheet" type="text/css" href="css/reset.css" />
		<link rel="stylesheet" href="css/public.css" />
		<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
		<script type="text/javascript" src="js/jianrong.js"></script>
		 -->
		 <script type="text/javascript" src="${ctx}/js/fastclick.js"></script>
	
	<script type="text/javascript">
		 var currentPage = 2;    
		//ajax请求评价咨询接口
		function queryEvaluate(flag){
			var comment_url;
			var evaluateFlag = $("#evaluateFlag").val();
			if(evaluateFlag=="false"){
				comment_url = "${ctx}/consultComment/queryConsultAll.do";
			}else{
				comment_url = "${ctx}/consultComment/queryConsult.do";
			}
			var goodsId = $("#goodsId").val();
			var statusext = null;
			if(flag!=null){
				statusext = flag;
				$("#evaluateStatus").val(flag);
			}
            $.ajax({
  					url : comment_url,
  					type : "post",
  					//	dataType : 'json',
  					data : {"status":statusext,"goodsId":goodsId,"type":2},
  					async : false,
  					success : function(data, status) {
  						var totalRecords = data.totalRecords; //获取总数
  						var currentPageS = data.currentPage; //获取当前页数
  						currentPage = 2 ;
  						var resultList = data.resultList;  //获取返回的集合数据
  						var evaluateFlag = data.evaluateFlag; //是否个人评价
	         			$("#evaluateFlag").val(evaluateFlag);
  						//移除已有的标签元素数据
  						$("#consult_comment").empty();
  						var html = optionByHtml(resultList);
  						html+="<li class='pageRefresh' onclick='clickRefresh();'>点击加载更多<img src='${ctx}/image/huan.png' alt='刷新' /></li>";
						$("#consult_comment").append(html);
	   				},
	   				error : function(xhr, status, e) {
	   					alert("失败错误信息"+e)
	   				}
        	 });
         } 
	/****评价分页请求*****/
	function clickRefresh(){
		var comment_url;
		var evaluateFlag = $("#evaluateFlag").val();
		if(evaluateFlag=="false"){
			comment_url = "${ctx}/consultComment/queryConsultAll.do";
		}else{
			comment_url = "${ctx}/consultComment/queryConsult.do";
		}
		var evaluateStatus = $("#evaluateStatus").val();
		 // 加载菜单的数据
	    $.ajax({
	       	url : comment_url,
			type : "post",
			data : {"status":evaluateStatus,"type":2,"currPage":currentPage},
	      	async : false,
	        success: function(data,status){
	        	currentPage =data.currentPage;
	        	currentPage++;
	         	var resultList = data.resultList;
	         	var totalRecords = data.totalRecords; //总条数
	         	var evaluateFlag = data.evaluateFlag; //是否个人评价
	         	$("#evaluateFlag").val(evaluateFlag);
	        	if(resultList!=null && resultList.length>0){
	       			var optionHtml = optionByHtml(resultList);
	        	}else{
	        		$(".pageRefresh").text("数据加载完毕！！！")
	        		$(".pageRefresh").removeAttr("onclick");  //移除事件
	        	}	
	        	$(".pageRefresh").before(optionHtml);
	       	},
	        error: function(xhr, type){
	            alert('Ajax error!');
	        }
	    });
	}

	/***拼装html*****/
	function optionByHtml(resultList){
		var optionHtml = "";
		$.each(resultList, function(i,result){      
			var createTime = result.createTime;
			var createTimeStr="";
			if(createTime!=null){
				createTimeStr=timeStamp2String(createTime);
			}
			var specInfo = result.specInfo;
			if(specInfo==null){
				specInfo="";
			}
			optionHtml+="	<li class='allEva'> "
					var mImg = result.mImg;
					if(mImg!=null && mImg!=''){
						optionHtml+="	<img src='${baseFile}"+mImg+"' alt='' /> "
					}else{
						optionHtml+="	<img src='${ctx}/image/tx54.png' alt='' /> "
					}
					optionHtml+="	<span>"+result.memberName+"</span><span class='classTime'>"+createTimeStr+"</span>"
					+"</li> "
					+"<li class='evaluatesT'> "
					+"	<span>"+specInfo+"</span> "
					+"</li> "
					+"<li class='evaluatesWord'>"+result.consultContent+"</li> "
					+"<li class='evaluatesI'> "
					if(result.filePicture!=null && result.filePicture!=""){
						optionHtml+=" <img src='${baseFile}"+result.filePicture+"' alt='' /> "
					}
					if(result.filePicture2!=null && result.filePicture2!=""){
						optionHtml+=" <img src='${baseFile}"+result.filePicture2+"' alt='' /> "
					}
					if(result.filePicture3!=null && result.filePicture3!=""){
						optionHtml+=" <img src='${baseFile}"+result.filePicture3+"' alt='' /> "
					}
					optionHtml+=" </li> "
				//	+"<li class='evaluatesW allEval'>浏览368次</li> "
					+"<li style='border-bottom:1px blue dashed;'></li> ";
		});
		return optionHtml;
	}

	 //格式化日期时间 
        function timeStamp2String(time){
		    var datetime = new Date();
		    datetime.setTime(time);
		    var year = datetime.getFullYear();
		    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
		    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
		    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
		    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
		    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
		    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
		}
	</script>
	</head>
	<body>
		<input type="hidden" name="goodsId" id="goodsId" value="${goodsId}"> 
		<input type="hidden" name="evaluateStatus" id="evaluateStatus" value="0">
		<input type="hidden" name="evaluateFlag" id="evaluateFlag" value="${evaluateFlag}">
		<header>
			<nav class="headerTwo">
				<img src="${ctx}/image/bg.png" alt="" />
				<a href="javascript:history.back(-1)" class="fl"><img src="${ctx}/image/return.png" alt="" /></a>
				<h2>全部评价</h2>				
				<%@include file="../common/headerR.jsp"%> 
			</nav>
		</header>
		<ul class="evaluate clearfix allEv sanWang">
			<li class="fl" onclick="queryEvaluate('0')">全部</li>
			<li class="fl" onclick="queryEvaluate('3')">好评</li>
			<li class="fl" onclick="queryEvaluate('2')">中评</li>
			<li class="fl" onclick="queryEvaluate('1')">差评</li>
			<li class="fl" onclick="queryEvaluate('4')">有图</li>
		</ul>
		<div class="alll" >
			<ul class="evaluates" id="consult_comment">
				<c:forEach items="${resultList}" var="comment">
					<li class="allEva">
						<c:choose>
							<c:when test="${comment.mImg!=null and comment.mImg!=''}">
								<img src="${baseFile}${comment.mImg}" alt="" />
							</c:when>
							<c:otherwise><img src="${ctx }/image/tx54.png" alt="" /></c:otherwise>
						</c:choose>
						<span>${comment.memberName }</span>
						<span class="classTime"><fmt:formatDate value='${comment.createTime}' pattern='yyyy-MM-dd HH:mm:ss'/></span>
					</li>
					<li class="evaluatesT">
						<span>${comment.specInfo}</span>
					</li>
					<li class="evaluatesWord">${comment.consultContent }</li>
					 <li class="evaluatesI">
					 	<c:if test="${comment.filePicture != null and comment.filePicture!=''}">
					 		<img src="${baseFile}${comment.filePicture}" alt="" />
					 	</c:if>
						<c:if test="${comment.filePicture2 != null and comment.filePicture2!=''}">
					 		<img src="${baseFile}${comment.filePicture2}" alt="" />
					 	</c:if>
					 	<c:if test="${comment.filePicture3 != null and comment.filePicture3!=''}">
					 		<img src="${baseFile}${comment.filePicture3}" alt="" />
					 	</c:if> 
					</li> 
					<li style="border-bottom:1px blue dashed;"></li>
				</c:forEach>
					<li class="pageRefresh" onclick="clickRefresh();">点击加载更多<img src="${ctx}/image/huan.png" alt="刷新" /></li>
			</ul>
		</div>
       <script type="text/javascript" src="${ctx}/js/public.js"></script>
	</body>
</html>
